package dev;

import processing.core.PApplet;
import peasy.*;
import peasy.PeasyCam.Constraint;
import peasy.org.apache.commons.math.geometry.Vector3D;
import lll.wrj4P5.*;
import lll.Loc.*;

/**
 * 
 * Space_Veiwer.drawObject();
  Space_Veiwer.drawStage();
 */
class Space_Veiwer extends PeasyCam {
 
  private PApplet parent;
  double currDistance = 250;
  float eyeX = 0;
 

 //pens = remote.irLights;
 // Robo_Sketch r = new Robo_Sketch();
 // IrPen4P5 r = new IrPen4P5(parent, null, false);

  Space_Veiwer(PApplet p5, double currDistance) {   
  
    super(p5,currDistance);
    parent = p5;
  
  }
 


 public void drawStage(){
	    int stageSize = 100;
	    int gridSize = 10;
	    parent.stroke(255,50);
	    for (int i = -stageSize; i<=stageSize;i=i+gridSize){
	    	parent.line(i,-stageSize,i,stageSize);  
	    }
	    for (int j = -stageSize;j<=stageSize;j=j+gridSize){
	    	parent.line(-stageSize,j,stageSize,j);
	     }
	    parent.stroke(255);
	    
	    parent.line(-stageSize, 0, 0, stageSize, 0, 0);
	    parent.line(0, -stageSize, 0, 0, stageSize, 0);
	    parent.line(0, 0, -stageSize, 0, 0, stageSize);
    
  // drawObject();
}

 public void drawObject(){
	 	 
    //noStroke();
    parent.fill(255,30);
    parent.box(90);

  }
 
 
 
 
public void penZoom(final double delta)
	{
		safeSetDistance(distance + delta * Math.sqrt(distance * .2));
	}

public void penPan(final double dxMouse, final double dyMouse)
{
	final double panScale = Math.sqrt(distance * .005);
	pan(dragConstraint == Constraint.Y ? 0 : -dxMouse * panScale,
			dragConstraint == Constraint.X ? 0 : -dyMouse * panScale);
}

public void penRotate(final double dx, final double dy, final float xLoc, final float yLoc)
{
	final Vector3D u = LOOK.scalarMultiply(100 + .6 * startDistance).negate();

	if (dragConstraint != Constraint.X)
	{
		final double rho = Math.abs((parent.width) - xLoc) / (parent.width / 2d);
		final double adz = Math.abs(dy) * rho;
		final double ady = Math.abs(dy) * (1 - rho);
		final int ySign = dy < 0 ? -1 : 1;
		final Vector3D vy = u.add(new Vector3D(0, ady, 0));
		rotateX.impulse(Vector3D.angle(u, vy) * ySign);
		final Vector3D vz = u.add(new Vector3D(0, adz, 0));
		rotateZ.impulse(Vector3D.angle(u, vz) * -ySign
				* (xLoc < parent.width / 2 ? -1 : 1));
	}

	if (dragConstraint != Constraint.Y)
	{
		final double eccentricity = Math.abs((parent.height / 2d) - yLoc) / (parent.height / 2d);
		final int xSign = dx > 0 ? -1 : 1;
		final double adz = Math.abs(dx) * eccentricity;
		final double adx = Math.abs(dx) * (1 - eccentricity);
		final Vector3D vx = u.add(new Vector3D(adx, 0, 0));
		rotateY.impulse(Vector3D.angle(u, vx) * xSign);
		final Vector3D vz = u.add(new Vector3D(0, adz, 0));
		rotateZ.impulse(Vector3D.angle(u, vz) * xSign
				* (yLoc > parent.height / 2 ? -1 : 1));
	}
}

}
